package com.sun.androidexerciseproject.widget.activity.ui;

import android.app.Activity;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

import com.gyf.immersionbar.ImmersionBar;
import com.sun.androidexerciseproject.widget.R;
import com.sun.androidexerciseproject.widget.adapter.ViewPagerAdapter;
import com.sun.androidexerciseproject.widget.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/3 0003.
 */

public class ViewPagerActivity extends Activity {
    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private ViewPagerAdapter mViewPagerAdapter;
    private List<String> mList = new ArrayList<>();
    private List<View> mViews = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        LogUtil.log("ViewPagerActivity onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager);
        initList();
        initWidgets();
        ImmersionBar.with(this).navigationBarColor(R.color.colorPrimary).init();
    }

    private void initWidgets() {
        mViewPager = findViewById(R.id.view_pager);
        mTabLayout = findViewById(R.id.tab_layout);
        mViewPagerAdapter = new ViewPagerAdapter(mList, mViews);
        mViewPager.setAdapter(mViewPagerAdapter);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void initList() {
        String[] city = getResources().getStringArray(R.array.auto_text);
        int len = city.length;
        for (String i : city) {
            mList.add(i);
        }
        LayoutInflater inflater = LayoutInflater.from(this);
        View view1 = inflater.inflate(R.layout.layout_button, null);
        View view2 = inflater.inflate(R.layout.layout_button, null);

        View view3 = inflater.inflate(R.layout.layout_button, null);

        View view4 = inflater.inflate(R.layout.layout_button, null);

        View view5 = inflater.inflate(R.layout.layout_button, null);

        mViews.add(view1);
        mViews.add(view2);

        mViews.add(view3);

        mViews.add(view4);

        mViews.add(view5);

    }
}
